/*
 * Copyright (c) 2008-2016 Haulmont.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * The button caption font weight.
 * @group button
 */
$cuba-button-font-weight: $v-font-weight !default;
/**
 * Defines whether button with primary action should be highlighted.
 * @group button
 */
$cuba-highlight-primary-action: false !default;
/**
 * Whether linkButton caption should be placed in one row or can wrap onto multiple rows.
 * @group linkButton
 */
$cuba-link-button-caption-wrap: true !default;

@mixin halo-button($primary-stylename: v-button) {
  $link-padding: 2px;

  .#{$primary-stylename} {
    .v-button-caption {
      font-weight: $cuba-button-font-weight;
    }

    &.c-cm-button .v-button-caption {
      font-weight: $v-font-weight;
    }
  }

  .#{$primary-stylename}-link {
    text-align: left;
    padding-left: $link-padding;
    padding-right: $link-padding;
    border: 1px dashed transparent;
    height: auto;

    .#{$primary-stylename}-caption {
      @include user-select(text);
    }

    &:focus:after {
      @include box-shadow(none);
    }
  }

  .#{$primary-stylename}-empty-caption {
    .#{$primary-stylename}-caption {
      display: none;
    }

    .#{$primary-stylename}-wrap {
      .v-icon {
        margin-right: 0;
      }
    }
  }

  .v-disabled.#{$primary-stylename}-link:focus {
    border-color: transparent;
  }

  .#{$primary-stylename}-link:focus {
    outline: none;
    border-color: $v-link-font-color;
  }

  .#{$primary-stylename}-borderless,
  .#{$primary-stylename}-borderless-colored {
    &:focus {
      &:after {
        border: 1px solid $v-focus-color;
      }
    }

    &:after {
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
    }
  }

  @if $cuba-highlight-primary-action {
    .#{$primary-stylename}.c-primary-action {
      @include valo-button-style($background-color: $v-focus-color, $unit-size: null);
    }
  }

  .#{$primary-stylename}.link {
    display: inline-flex;

    &.v-has-height {
      overflow-y: hidden;
    }

    &.v-has-width {
      overflow-x: hidden;
    }

    &:before,
    &:after {
      display: none;
    }
  }

  .#{$primary-stylename}.link .#{$primary-stylename}-caption {
    white-space: normal;
    overflow-wrap: normal;
  }

  .#{$primary-stylename}.link .#{$primary-stylename}-wrap {
    margin-bottom: auto;
    margin-top: auto;
  }

  @if $cuba-link-button-caption-wrap == false {
    .#{$primary-stylename}.link {
      display: inline-block;

      &.v-has-height {
        overflow-y: inherit;
      }

      &.v-has-width {
        overflow-x: inherit;
      }

      &:before,
      &:after {
        display: inline-block;
      }
    }

    .#{$primary-stylename}.link .#{$primary-stylename}-caption {
      white-space: nowrap;
    }

    .#{$primary-stylename}.link .#{$primary-stylename}-wrap {
      margin-bottom: 0;
      margin-top: 0;
    }
  }
}
